]> git.r.bdr.sh - rbdr/super-polarity/blobdiff - Super Polarity/SuperPolarity.cs
Protoshow sprint.
[rbdr/super-polarity] / Super Polarity / SuperPolarity.cs
index c43582eda87f868913b405e0824ad6f8db0e3eb7..8125f8cdcea147b608d2f4b5c074bd577201cee3 100644 (file)
@@ -7,6 +7,8 @@ using Microsoft.Xna.Framework.Graphics;
 using Microsoft.Xna.Framework.Input;
 using Microsoft.Xna.Framework.Storage;
 using Microsoft.Xna.Framework.GamerServices;
+using Microsoft.Xna.Framework.Media;
+using Microsoft.Xna.Framework.Audio;
 using SuperPolarity;
 #endregion
 
@@ -17,21 +19,35 @@ namespace SuperPolarity
     /// </summary>
     public class SuperPolarity : Game
     {
-        public static GraphicsDeviceManager graphics;
+        public GraphicsDeviceManager graphics;
         SpriteBatch spriteBatch;
 
-        // Input Handler
-        KeyboardState currentKeyboardState;
-        GamePadState currentGamePadState;
+        public static int OutlierBounds;
 
-        MainShip player;
+        public Player Player;
+
+        Screen EntryScreen;
+
+        protected Song TitleSong;
+        protected Song GameSong;
+        protected SoundEffect GameOverSound;
 
         public SuperPolarity()
             : base()
         {
-            SuperPolarity.graphics = new GraphicsDeviceManager(this);
-            SuperPolarity.graphics.PreferMultiSampling = true;
+            graphics = new GraphicsDeviceManager(this);
+            graphics.PreferMultiSampling = true;
+            graphics.PreferredBackBufferWidth = 1280;
+            graphics.PreferredBackBufferHeight = 720;
+            graphics.ToggleFullScreen();
+
             Content.RootDirectory = "Content";
+            ActorFactory.SetGame(this);
+            ParticleEffectFactory.SetGame(this);
+            ActorManager.SetGame(this);
+            ScreenManager.SetGame(this);
+
+            EntryScreen = (Screen)new TitleScreen(this);
         }
 
         /// <summary>
@@ -42,9 +58,20 @@ namespace SuperPolarity
         /// </summary>
         protected override void Initialize()
         {
-            player = new MainShip();
-
             base.Initialize();
+
+            InputController.RegisterEventForKey("fullScreenToggle", Keys.F11);
+            InputController.Bind("fullScreenToggle", HandleFullScreenToggle);
+
+            EntryScreen.Initialize();
+
+            OutlierBounds = 100;
+        }
+
+        protected void HandleFullScreenToggle(float value)
+        {
+            graphics.ToggleFullScreen();
+            graphics.ApplyChanges();
         }
 
         /// <summary>
@@ -53,12 +80,17 @@ namespace SuperPolarity
         /// </summary>
         protected override void LoadContent()
         {
+
+            MediaPlayer.IsRepeating = true;
+            GameSong = Content.Load<Song>("Sound\\polaritytheme.wav");
+            GameOverSound = Content.Load<SoundEffect>("Sound\\gameover");
+
             // Create a new SpriteBatch, which can be used to draw textures.
             spriteBatch = new SpriteBatch(GraphicsDevice);
 
-            Vector2 playerPosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X, GraphicsDevice.Viewport.TitleSafeArea.Y + GraphicsDevice.Viewport.TitleSafeArea.Height / 2);
+            ScreenManager.Push(EntryScreen);
 
-            player.Initialize(Content, Content.Load<Texture2D>("Graphics\\main-ship"), playerPosition);
+            Player = new Player(this);
         }
 
         /// <summary>
@@ -80,10 +112,9 @@ namespace SuperPolarity
             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                 Exit();
 
-            // TODO: Add your update logic here
+            ScreenManager.Update(gameTime);
 
-            InputController.UpdateInput();
-            player.Update(gameTime);
+            Player.Update();
 
             base.Update(gameTime);
         }
@@ -98,11 +129,27 @@ namespace SuperPolarity
 
             spriteBatch.Begin();
 
-            player.Draw(spriteBatch);
+            ScreenManager.Draw(spriteBatch);
 
             spriteBatch.End();
 
             base.Draw(gameTime);
         }
+
+        public void PlaySong(string songName)
+        {
+            // temp stuff before media manager is in
+            if (songName == "game")
+            {
+                MediaPlayer.Play(GameSong);
+            }
+        }
+
+        public void GameOver()
+        {
+            MediaPlayer.Stop();
+            GameOverSound.Play();
+            ScreenManager.Pop();
+        }
     }
 }